package com.teemor.demo.utils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Description:
 * @author zhoulk
 * @date: 2020/5/6
 */
public class LRUCache<K,V> extends LinkedHashMap<K,V> {

    private int capacity; // Maximum number of items in the cache.

    public LRUCache(int capacity) {
        super(capacity+1, 1.0f, true); // Pass 'true' for accessOrder.
        this.capacity = capacity;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {
        return (size() > this.capacity);
    }
}
